package cn.sxt.common.userscenter.util;

import java.util.Date;
import java.util.Iterator;
import java.util.Map.Entry;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

/**
 * 定时执行工具类
 * @author Administrator
 *
 */
@Component("taskUtil")
public class TaskUtil {
	@Resource
	private DateFormatUtil dateFormatUtil;
	public void test(){
		ConstantFinalUtil.LOGGER.info("-------开始----token大小{}--",ConstantFinalUtil.TOKEN_MAP.size());
		Date nowDate = new Date();
		for (Iterator iterator = ConstantFinalUtil.TOKEN_MAP.entrySet().iterator(); iterator.hasNext();) {
			Entry me = (Entry) iterator.next();
			String key = me.getKey() + "";
			JSONObject usersJson = (JSONObject) me.getValue();
			/* 判断token是否过期 */
			String verifyStr = usersJson.get("verifyDate") + "";
			Date verifyDate = this.dateFormatUtil.parseDateTime(verifyStr);
			/* token有效期一分钟 */
			if(nowDate.getTime() - verifyDate.getTime() > 1000 * 60){
				ConstantFinalUtil.TOKEN_MAP.remove(key);
				ConstantFinalUtil.LOGGER.info("--键:{},值:{}",key,usersJson);
			}
		}
		ConstantFinalUtil.LOGGER.info("-------结束--token大小：{}----",ConstantFinalUtil.TOKEN_MAP.size());
	}
}
